<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PageContent
 *
 * @author Tartharia
 */
class PageContent extends CModel{
    private $db;
    protected static $_page_id;
    protected $page_id;
    protected $rows = array();
    public $title, $tabs = array();


    private function __construct($page_id) {
        $this->page_id = $page_id;
        $this->db = Yii::app()->db;
        $this->getPageContent();
        $this->setTabs();
    }
    
    public static function _init($page_id)
    {
        if(empty(self::$_page_id))
            self::$_page_id = new PageContent($page_id);
        return self::$_page_id;
        
    }
    public function getPageId()
    {
        return $this->page_id;
    }

    protected function getPageContent()
    {
        $sql_query = "SELECT * FROM `{{pages}}` WHERE id={$this->page_id}";
        $command =  $this->db->createCommand($sql_query);
        $row = $command->queryRow();
        $this->title = $row['title'];
        
        $sql_query = "SELECT * FROM `{{pagescontent}}` WHERE page_id={$this->page_id}";
        $command = $this->db->createCommand($sql_query);
        $this->rows = $command->queryAll();
    }

    protected function setTabs()
    {
        foreach ($this->rows as $row) {
            array_push($this->tabs, array(
                $row['tab_attribute'] => $row['tab_title'],
                'content' => $row['tab_content'])
                );
        }
    }

    public function attributeNames() {
        ;
    }
}

?>
